<ResourceDictionary
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:dropShadow="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
  xmlns:helpers="clr-namespace:MissedMemo.MeatAndCheeseDisc.UIHelperClasses;assembly=UIHelperClasses"
  xmlns:data="clr-namespace:MissedMemo.MeatAndCheeseDisc.OrderMonitorService.OrderProcessing;assembly=OrderMonitorServiceAbstraction"
  xmlns:local="clr-namespace:MissedMemo.MeatAndCheeseDisc.OrderMonitor">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="resStyles.xaml" />
    </ResourceDictionary.MergedDictionaries>
    

    <local:SizeToAbbreviationConverter x:Key="SizeToAbbreviationConverter" />
    <local:CancelStateToOpacityConverter x:Key="CancelStateToOpacityConverter" />
    <helpers:FormattedTextConverter x:Key="FormattedTextConverter" />
    
    
    <DataTemplate DataType="{x:Type data:Pizza}" x:Key="PizzaDataTemplate">
        
        <Grid>

            <!-- performant drop shadow (recommended in place of bitmap effects - may no longer be needed with .Net 3.5 RTM)-->
            <dropShadow:SystemDropShadowChrome Margin="8" CornerRadius="12" Name="FramingDropShadow"
             Opacity="{Binding IsCancelled, Converter={StaticResource CancelStateToOpacityConverter}}" >
                
                <Border Name="ItemBorder" Padding="5" Style="{StaticResource DefaultKitchenOrderStyle}" >
                    
                    <Grid>
                        
                        <Grid.Resources>
                            <!-- TextBlock.VerticalAlignment can't be applied via border style -->
                            <Style TargetType="TextBlock" >
                                <Setter Property="TextAlignment" Value="Center" />
                                <Setter Property="VerticalAlignment" Value="Center" />
                            </Style>
                        </Grid.Resources>
                        
                        <Grid.RowDefinitions>
                            <RowDefinition Height="28" />
                            <RowDefinition Height="28" />
                            <RowDefinition Height="auto" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="80" />
                            <ColumnDefinition Width="40"/>
                        </Grid.ColumnDefinitions>

                        
                        <!-- Order Number and Elapsed Time -->

                        <Rectangle Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2" RadiusX="8" RadiusY="8"
                                   Stroke="{StaticResource brushOrderHeaderOutline}" Fill="{StaticResource brushOrderHeaderBackground}" />

                        <TextBlock Grid.Column="0" Grid.Row="0" Foreground="{StaticResource brushOrderNumberText}" Text="{Binding NowServingNumber,
                            Converter={StaticResource FormattedTextConverter}, ConverterParameter='Order# {0}'}" />
                        <TextBlock Grid.Column="1" Grid.Row="0" Foreground="{StaticResource brushElapsedTimeText}" Text="{Binding Timer.ElapsedTime,
                            Converter={StaticResource FormattedTextConverter}, ConverterParameter='{}{0:mm:ss}'}" />
                        
                        
                        <!-- Pizza Type and Size -->
                        
                        <TextBlock Grid.Column="0" Grid.Row="1" Text="{Binding Type}" />
                        
                        <Grid Grid.Column="1" Grid.Row="1">
                            <Ellipse Stroke="{StaticResource brushPizzaSizeOutline}" Width="18" Height="18" />
                            <TextBlock Text="{Binding Size, Converter={StaticResource SizeToAbbreviationConverter}}" /> 
                        </Grid>
                        
                        
                        <!-- Pizza Customization -->
                    
                        <Grid Grid.Row="2" Grid.ColumnSpan="2" Margin="3" >
                            
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*" />
                                <RowDefinition Height="auto" />
                            </Grid.RowDefinitions>
                            
                            <Rectangle Grid.RowSpan="2" Style="{StaticResource PizzaOptionBorderStyle}"
                                       Visibility="{Binding HasOptionsOrInstructions, Converter={StaticResource BooleanToVisibilityConverter}}"/>
                            
                            <ListBox Grid.Row="0" Margin="3" Background="{x:Null}" BorderThickness="0" IsEnabled="False"
                                     ItemsSource="{Binding Options}" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                                     Visibility="{Binding HasOptions, Converter={StaticResource BooleanToVisibilityConverter}}" >
                                
                                <!-- Disabled list is not interactive, but we still need to override disabled text color -->
                                
                                <ListBox.ItemContainerStyle>
                                    <Style TargetType="ListBoxItem">
                                        <Style.Triggers>
                                            <Trigger Property="IsEnabled" Value="false">
                                                <Setter Property="Foreground" Value="{StaticResource brushPizzaOptionsBorder}"/>
                                            </Trigger>
                                        </Style.Triggers>
                                    </Style>
                                </ListBox.ItemContainerStyle>
                                
                            </ListBox>
                                            
                            <Line Grid.Row="1" Stroke="{StaticResource brushPizzaOptionsBorder}" X2="120"
                                  Visibility="{Binding HasOptionsAndInstructions, Converter={StaticResource BooleanToVisibilityConverter}}" />
                            
                            <TextBlock Grid.Row="1" Margin="3" Text="{Binding SpecialInstructions}" TextWrapping="Wrap"
                                       Visibility="{Binding HasInstructions, Converter={StaticResource BooleanToVisibilityConverter}}"/>
                            
                        </Grid>
                        
                        
                        <!-- Close Button -->
                        
                        <Button Grid.Row="0" Grid.Column="1" Name="CloseButton" Width="22" Height="22" Margin="0,-24,-54,0" Style="{StaticResource CloseButtonStyle}"
                                Visibility="Collapsed" Command="{x:Static local:CustomCommands.CompleteOrderItem}" ToolTip="Click to mark item &quot;finished&quot;" />
                        
                    </Grid>
                </Border>
            </dropShadow:SystemDropShadowChrome>

            <!-- "Cancelled" overlay -->
            <TextBlock Text="CANCELLED" Style="{StaticResource CancelAnnotationStyle}" />
            
        </Grid>
        
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListBoxItem}}" Value="True" >
                <Setter TargetName="ItemBorder" Property="Style" Value="{StaticResource SelectedKitchenOrderStyle}" />
                <Setter TargetName="CloseButton" Property="Visibility" Value="Visible" />
                <Setter TargetName="FramingDropShadow" Property="Margin" Value="8,20,20,8" />
                <Setter TargetName="FramingDropShadow" Property="LayoutTransform">
                    <Setter.Value>
                        <ScaleTransform CenterX="0" CenterY="0" ScaleY="1.25" ScaleX="1.25" />
                    </Setter.Value>
                </Setter>
            </DataTrigger>
        </DataTemplate.Triggers>
        
    </DataTemplate>
    
</ResourceDictionary>